package com.gw.quotes.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

import com.gw.quotes.R;
import com.gw.quotes.activity.fragment.GoodsFragment0;
import com.gw.quotes.activity.fragment.GoodsFragment1;
import com.gw.quotes.activity.fragment.GoodsFragment2;
import com.gw.quotes.activity.fragment.GoodsFragment3;
import com.gw.quotes.adapter.GiftAdapter;
import com.yxw.view.NoScrollListView;

public class GoodsIntroduceActivity extends BaseFragmentActivity {

	//private Goods goods;
	private GiftAdapter giftAdapter;

	private TextView title, goods_no, goods_sel_price, goods_org_price;
	private NoScrollListView giftListview;
	// 定义FragmentTabHost对象
	private FragmentTabHost mTabHost;
	// 定义一个布局
	private LayoutInflater layoutInflater;
	// 定义数组来存放Fragment界面
	private Class fragmentArray[] = { GoodsFragment0.class,
			GoodsFragment1.class, GoodsFragment2.class, GoodsFragment3.class };
	// Tab选项卡的文字
	private String mTextviewArray[] = { "商品介绍", "规格参数", "协议供应商", "成交记录" };
	// 定义数组来存放按钮图片
	private int mImageViewArray[] = { R.drawable.bg_goods, R.drawable.bg_goods,
			R.drawable.bg_goods, R.drawable.bg_goods };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_goods_introduce);
		getIntentData();
		initView();
		initTabhost();
	}

	private void getIntentData() {
		Intent intent = getIntent();
		//goods = (Goods) intent.getSerializableExtra("goodsInfo");
	}

	private void initView() {
//		giftAdapter = new GiftAdapter(this, R.layout.item_gift, goods.getGift());
		title = (TextView) findViewById(R.id.title);
		goods_no = (TextView) findViewById(R.id.goods_no_text);
		goods_sel_price = (TextView) findViewById(R.id.goods_selling_price_text);
		goods_org_price = (TextView) findViewById(R.id.goods_original_price_text);
		giftListview = (NoScrollListView) findViewById(R.id.gift_listview);
//		title.setText(goods.getGoods_title());
//		goods_no.setText(goods.getGoods_no());
//		goods_sel_price.setText(goods.getGoods_selling_price());
//		goods_org_price.setText(goods.getGoods_original_price());
		giftListview.setAdapter(giftAdapter);
	}

	private void initTabhost() {
		// 实例化布局对象
		layoutInflater = LayoutInflater.from(this);

		// 实例化TabHost对象，得到TabHost
		mTabHost = (FragmentTabHost) findViewById(R.id.ftabhost);
		mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

		// 得到fragment的个数
		int count = fragmentArray.length;

		for (int i = 0; i < count; i++) {
			// 为每一个Tab按钮设置图标、文字和内容
			TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i])
					.setIndicator(getTabItemView(i));
			// 将Tab按钮添加进Tab选项卡中
			mTabHost.addTab(tabSpec, fragmentArray[i], null);
			// 设置Tab按钮的背景
			// mTabHost.getTabWidget().getChildAt(i)
			// .setBackgroundResource(R.drawable.bg_goods);
		}
	}

	private View getTabItemView(int index) {
		View view = layoutInflater.inflate(R.layout.item_tabhost_goods, null);

		// ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
		// imageView.setImageResource(mImageViewArray[index]);

		TextView textView = (TextView) view.findViewById(R.id.goods_text);
		textView.setText(mTextviewArray[index]);
		// textView.setBackgroundResource(mImageViewArray[index]);

		return view;
	}

	public void back(View v) {
		finish();
	}

//	public Goods getGoods() {
//		return goods;
//	}

}
